#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ipc.h>

#define N 32
struct msg
{
	long type;
	unsigned char text[N];
};

struct msg msg_buf = {0, {0}};

int main(int argc, const char *argv[])
{
	key_t key; 
	int msgid; 
	char device[6] = {0};

	memset(&msg_buf, 0, sizeof(msg_buf));
	if((key = ftok("/", 'b')) < 0)
	{
		perror("ftok");
		exit(1);
	}

	msgid = msgget(key,IPC_CREAT|IPC_EXCL|0666);
	if(msgid == -1)
	{
		if(errno == EEXIST)
		{
			msgid = msgget(key, 0666);
		}
		else{
		perror("msgget");
		exit(1);
	}
	}
	msgrcv(msgid, &msg_buf, sizeof(msg_buf) - sizeof(long), 1L, 0);
	printf("%d\n",__LINE__);
	printf("%#x\n", msg_buf.type);
	printf("%#x\n", msg_buf.type);
	puts("-------------");
	printf("%c\n", msg_buf.text[0]);
	return 0;
}
